﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GBH.Models;

namespace GBH.Providers
{
    public class StockProvider
    {
        private int _maxStock;
        private int _minStock;
        private int _ropStock;

        public int MaxStock
        {
            get
            {
                return _maxStock;
            }
            set
            {
                _maxStock = value;
            }
        }

        public int MinStock
        {
            get
            {
                return _minStock;
            }
            set
            {
                _minStock = value;
            }
        }

        public int RopStock
        {
            get
            {
                return _ropStock;
            }
            set
            {
                _ropStock = value;
            }
        }

        public List<sell_out> getDaySale(DateTime From, DateTime To)
        {
            using (var ctx = new GBHEntities())
            {
                var queues = (from daySale in ctx.sell_out
                              where daySale.date_time >= From && daySale.date_time <= To
                              select daySale);

                return queues.ToList();
            }
        }

        public int getDaySale(List<sell_out> sellOut)
        {
            return sellOut.Sum(s => s.qty ?? 0) / sellOut.Count;
        }
    }
}